//: C03:Static.cpp
// Using a static variable in a function
#include <iostream>
using namespace std;
/*
Compile and run Static.cpp. 
Remove the static keyword from the code, compile and run it again, and explain what happens.
*/

void func() {
  static int i = 0;
  cout << "i = " << ++i << endl;
}

int main() {
  for(int x = 0; x < 10; x++)
    func();
} 
/*
有static的输出：
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
i = 10
*/

/*
没有static的输出：
i = 1
i = 1
i = 1
i = 1
i = 1
i = 1
i = 1
i = 1
i = 1
i = 1
*/